package com.itheima.job;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;

    public void clearImgsResource() {
        Jedis jedis = jedisPool.getResource();
        Set<String> unImgs = jedis.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_RESOURCES_DB);
        if (unImgs != null && unImgs.size() > 0) {
            for (String unImg : unImgs) {
                jedis.srem(RedisConstant.SETMEAL_PIC_RESOURCES, unImg);
                QiniuUtils.deleteFileFromQiniu(unImg);
                System.out.println("删除无用图片" + unImg);
            }
        }
        jedis.close();
    }
}
